package com.guava.collection;

import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.collect.MutableClassToInstanceMap;

/**
 * ClassToInstanceMapTester--GuavaTest
 *
 * @author: Jovi
 * @createTime: 2018-05-11 15:28
 **/
public class ClassToInstanceMapTester {

    public static void main(String[] args) {
        MutableClassToInstanceMap<Number> map = MutableClassToInstanceMap.create();
        map.putInstance(Integer.class, 100);
        map.putInstance(Float.class, 10.01f);
        System.out.println(map.getInstance(Integer.class));
        System.out.println(map.getInstance(Float.class));

        ImmutableClassToInstanceMap<Number> map1 =
                new ImmutableClassToInstanceMap.Builder<Number>()
                        .put(Integer.class, 100)
                        .put(Float.class, 10.01f)
                        .build();

        // throws UnsupportedOperationException
        // map1.putInstance(Integer.class, 1000);
        // map1.put(Integer.class, 1000);


        System.out.println(map.getInstance(Integer.class));
        ImmutableClassToInstanceMap<Number> map2 = ImmutableClassToInstanceMap.copyOf(map);
        System.out.println(map2.getInstance(Float.class));

    }
}
